package com.czl.module_user.fragment

import com.alibaba.android.arouter.facade.annotation.Route
import com.annimon.stream.Collectors
import com.annimon.stream.Stream
import com.blankj.utilcode.util.StringUtils
import com.czl.base.base.BaseFragment
import com.czl.base.config.AppConstants
import com.czl.base.util.ChoiceImgHelper
import com.czl.base.util.DialogHelper
import com.czl.module_user.BR
import com.czl.module_user.R
import com.czl.module_user.databinding.FragmentPeopleDetailBinding
import com.czl.module_user.viewmodel.PeopleDetailViewModel
import java.util.*

/**
 *
 * @Description:人员详情
 * @Author: XCH
 * @CreateDate: 2022/2/16 16:47
 */
@Route(path = AppConstants.Router.User.F_PEOPLE_DETAIL)
class PeopleDetailFragment : BaseFragment<FragmentPeopleDetailBinding, PeopleDetailViewModel>() {

    override fun initContentView(): Int {
        return R.layout.fragment_people_detail
    }

    override fun initVariableId(): Int {
        return BR.viewModel
    }

    override fun initData() {
        if (arguments != null) {
            viewModel.peopleId = requireArguments().getString(AppConstants.BundleKey.PEOPLE_ID, "")
            viewModel.ownerId = requireArguments().getString(AppConstants.BundleKey.OWNER_ID, "")
            viewModel.peopleFrom.set(
                requireArguments().getInt(AppConstants.BundleKey.PEOPLE_FROM, 0)
            )
        }
        viewModel.tvTitle.set("人员详情")

        reload()
    }

    override fun initViewObservable() {
        viewModel.uc.choiceImgEvent.observe(this, {
            ChoiceImgHelper.ChoiceImg(this,
                { result -> result[0]?.let { t -> viewModel.uploadHeadImg(t.compressPath) } },
                {})
        })

        viewModel.uc.saveCompleteEvent.observe(this, {
            back()
        })

        viewModel.uc.deleteEvent.observe(this, {
            DialogHelper.showBaseDialog(requireContext(), "", "确定删除该人员吗？") {
                viewModel.deleteHouseUser(it)
            }
        })

        viewModel.uc.deleteSuccessEvent.observe(this, {
            back()
        })

    }

    override fun reload() {
        super.reload()
        viewModel.getUserDetail()
    }

}